<html>
  <head>
	<meta charset="utf-8">
  </head>
  <body>
  <script>
	//alert("~s".match(/~/)?Number.parseInt("e"):1);
	var myx = 0;
	var myy = 0;
	var myz = 0;
	var blocks = {};
	function start(){
	    document.getElementById("e").innerHTML = "";
	    var doc = document.getElementById("i").value;
		var str = doc.split(" ");
		//for(x in str){alert(str[x]);}
		switch(str[0]){
		    case "fill":
	    	if(!doc.match(/^\/?fill (?:\~?[-0-9]*\.?[0-9]* ){6}.*$/)){err("语法错误;");throw "";}
	    	fill(str);
	    	break;
	    	case "get":
			if(!doc.match(/^\/?get(?: \~?[-0-9]*\.?[0-9]*){3}$/)){err("语法错误;");throw "";}
	     	get(str);
	    	break;
	      	case "tp":
		    if(!doc.match(/^\/tp(?: \~?[-0-9]*\.?[0-9]*){3}$/)){err("语法错误;");throw "";}
	    	tp(str);
		    break;
		    }
	    }
		//相对坐标
	function absu(n,mye){
	    if(n =="~")return mye;
	    return n.startsWith("~")?mye+Number.parseInt(n.substr(1)):Number.parseInt(n);
		}
	function fill(str){
		//alert(JSON.stringify(blocks));
		var counter = 0;
		var sx = absu(str[1],myx);
		var sy = absu(str[2],myy);
		var sz = absu(str[3],myz);
		var ex = absu(str[4],myx);
		var ey = absu(str[5],myy);
		var ez = absu(str[6],myz);
	    if(sx > ex){var tmp = ex;ex = sx;sx = tmp;}
		if(sy > ey){var tmp = ey;ey = sy;sy = tmp;}
		if(sz > ez){var tmp = ez;ez = sz;sz = tmp;}
	    for(var nx = sx;nx <= ex;nx++){
		    for(var ny = sy;ny <= ey;ny++){
			    for(var nz = sz;nz <= ez;nz++){
	                blocks[nx] = blocks[nx]||{};
		 			blocks[nx][ny] = blocks[nx][ny]||{};
				    blocks[nx][ny][nz] = str[7];
				    counter++;
					}
			    }
		    }
			document.getElementById("o").innerHTML = counter + "blocks has been placed";
		}
	function get(str){
	    try{
	    document.getElementById("o").innerHTML = "the block is " + 
		blocks[absu(str[1],myx)][absu(str[2],myy)][absu(str[3],myz)];
		}catch(e){document.getElementById("o").innerHTML = "the block is air";};
		}
	function tp(str){
	    myx = absu(str[1],myx);
		myy = absu(str[2],myy);
		myz = absu(str[3],myz);
		document.getElementById("o").innerHTML = "You have been teleport to "+myx+" "+myy+" "+myz;
	    }
		/*
		整数
	function nan(n){
	    n = Number.parseInt(n);
	    if(!Number.isInteger(n)){err("语法错误");throw "";}
		return n;
	    }
		*/
	function err(e){document.getElementById("e").innerHTML=e;}
  </script>
  <input type="text" id="i">
  <button onclick="start()">开始</button>
	<div id="o"></div>
	<div style="color:red" id="e"></div>
  </body>
</html>
